package com.LeeCode;

/**
 * 删除排序链表中的重复元素 II
 */

public class Code082 {
    public static void main(String[] args) {
        int[] arr = {1, 1, 1, 2, 3};
        ListNode head = Utils.arrayToListNode(arr);
        Utils.printListNode(new Code082().deleteDuplicates(head));
    }

    public ListNode deleteDuplicates(ListNode head) {

        ListNode dummyHead = new ListNode(0, head);
        ListNode cur = dummyHead;

        while (cur.next != null && cur.next.next != null) {
            int val = cur.next.val;
            if (cur.next.next.val == val) {
                while (cur.next != null && cur.next.val == val) {
                    cur.next = cur.next.next;
                }
            } else {
                cur = cur.next;
            }
        }
        return dummyHead.next;
    }
}
